package com.glsc.ngateway.common.base.repo.mysql.gateway.platform.system;

import com.glsc.ngateway.common.base.domain.mysql.gateway.system.SystemMainLog;
import com.glsc.ngateway.common.api.platform.dto.system.ParamSystemMainDto;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SystemMainLogRepository extends JpaRepository<SystemMainLog, Integer>, JpaSpecificationExecutor<SystemMainLog> {

    @Query(value = "select m from SystemMainLog m where 1=1 " +
            "and (:#{#paramSearchDto.opId} is null OR m.opId = :#{#paramSearchDto.opId})  " +
            "and (:#{#paramSearchDto.opName} is null OR m.opName LIKE CONCAT('%',:#{#paramSearchDto.opName},'%') )  " +
//            "and (:#{#paramSearchDto.processDefineKey} is null OR m.processDefineKey = :#{#paramSearchDto.processDefineKey} )  " +
//            "and (:#{#paramSearchDto.systemCode} is null OR m.systemCode = :#{#paramSearchDto.systemCode} )  " +
//            "and (:#{#paramSearchDto.beginDateLocalDate} is null OR m.processCreateTime >= :#{#paramSearchDto.beginDateLocalDate} )  " +
//            "and (:#{#paramSearchDto.endDateLocalDate} is null OR m.processCreateTime <= :#{#paramSearchDto.endDateLocalDate} )  " +
//            "and (:#{#paramSearchDto.hasProcessEnd} is null OR m.isClose = :#{#paramSearchDto.hasProcessEnd} )  " +
//            "and (coalesce(:#{#paramSearchDto.adminList}, null) is null or m.systemAdminAccount in (:#{#paramSearchDto.adminList})) " +
            "order by m.insertTime desc")
    List<SystemMainLog> searchByParam(ParamSystemMainDto paramSearchDto);
}